drop table if exists t1, t2, t3;
drop procedure if exists bug8850;
create table t1 (a int) engine=innodb;
create procedure bug8850() begin truncate table t1; insert t1 values (1); rollback; end;
set autocommit=0;
insert t1 values (2);
call bug8850();
commit;
select * from t1;
call bug8850();
set autocommit=1;
select * from t1;
drop table t1;
drop procedure bug8850;
drop function if exists bug10015_1;
drop function if exists bug10015_2;
drop function if exists bug10015_3;
drop function if exists bug10015_4;
drop function if exists bug10015_5;
drop function if exists bug10015_6;
drop function if exists bug10015_7;
drop procedure if exists bug10015_8;
create table t1 (id int) engine=innodb;
create table t2 (id int primary key, j int) engine=innodb;
insert into t1 values (1),(2),(3);
create function bug10015_1() returns int return (select count(*) from t1);
select *, bug10015_1() from t1;
drop function bug10015_1;
create function bug10015_2() returns int  begin declare i, s int; set i:= (select min(id) from t1); set s:= (select max(id) from t1); return (s - i); end;
select *, bug10015_2() from t1;
drop function bug10015_2;
create function bug10015_3() returns int  return (select max(a.id - b.id) from t1 as a, t1 as b where a.id >= b.id);
select *, bug10015_3() from t1;
drop function bug10015_3;
create function bug10015_4(i int) returns int  begin declare m int; set m:= (select max(id) from t2); insert into t2 values (i, m); return m; end;
select *, bug10015_4(id) from t1;
select * from t2;
drop function bug10015_4;
insert into t1 values (bug10015_5(4)), (bug10015_5(5));
select * from t1;
drop function bug10015_5;
create function bug10015_6(i int) returns int begin declare continue handler for sqlexception set @error_in_func:= 1; if (i = 5) then insert into t2 values (4, 0), (1, 0); end if; return i; end;
set @error_in_func:= 0;
insert into t1 values (bug10015_6(5)), (bug10015_6(6));
select @error_in_func;
select * from t1;
select * from t2;
drop function bug10015_6;
create function bug10015_7() returns int begin drop table t1; return 1; end;
drop function bug10015_7;
create function bug10015_7() returns int begin commit; return 1; end;
create procedure bug10015_8() alter table t1 add k int;
select *, bug10015_7() from t1;
drop procedure bug10015_8;
create procedure bug10015_8() start transaction;
select *, bug10015_7() from t1;
drop procedure bug10015_8;
create procedure bug10015_8() drop temporary table if exists t1_temp;
select *, bug10015_7() from t1;
drop procedure bug10015_8;
create procedure bug10015_8() commit;
select *, bug10015_7() from t1;
drop procedure bug10015_8;
drop function bug10015_7;
drop table t1, t2;
drop function if exists bug13825_0;
drop function if exists bug13825_1;
drop function if exists bug13825_2;
drop function if exists bug13825_3;
drop function if exists bug13825_4;
drop function if exists bug13825_5;
drop procedure if exists bug13825_0;
drop procedure if exists bug13825_1;
drop procedure if exists bug13825_2;
drop table if exists t1;
create table t1 (i int) engine=innodb;
create table t2 (i int) engine=innodb;
create function bug13825_2() returns int begin insert into t1 values (2); savepoint x; insert into t1 values (3); rollback to savepoint x; insert into t1 values (4); return 1; end;
create procedure bug13825_0() begin rollback to savepoint x; end;
create procedure bug13825_1() begin release savepoint x; end;
create procedure bug13825_2() begin savepoint x; end;
insert into t2 values (1);
create trigger t2_bi before insert on t2 for each row rollback to savepoint x;
create trigger t2_bu before update on t2 for each row release savepoint x;
create trigger t2_bd before delete on t2 for each row begin insert into t1 values (2); savepoint x; insert into t1 values (3); rollback to savepoint x; insert into t1 values (4); end;
create function bug13825_3(rb int) returns int begin insert into t1 values(1); savepoint x; insert into t1 values(2); if rb then rollback to savepoint x; end if; insert into t1 values(3); return rb; end;
create function bug13825_4() returns int begin savepoint x; insert into t1 values(2); rollback to savepoint x; return 0; end;
create function bug13825_5(p int) returns int begin savepoint x; insert into t2 values(p); rollback to savepoint x; insert into t2 values(p+1); return p; end;
set autocommit= 0;
begin ;
insert into t1 values (1);
savepoint x;
set @a:= bug13825_0();
insert into t2 values (2);
set @a:= bug13825_1();
update t2 set i = 2;
set @a:= bug13825_2();
select * from t1;
rollback to savepoint x;
select * from t1;
delete from t2;
select * from t1;
rollback to savepoint x;
select * from t1;
release savepoint x;
set @a:= bug13825_2();
select * from t1;
rollback to savepoint x;
delete from t1;
commit;
begin;
insert into t1 values (5);
savepoint x;
insert into t1 values (6);
